package com.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.annotation.IgnoreAuth;
import com.utils.R;

import java.util.*;

/**
 * 统计数据控制器
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    /**
     * 获取统计概览数据
     */
    @IgnoreAuth
    @GetMapping("/overview")
    public R getOverview() {
        Map<String, Object> data = new HashMap<>();
        data.put("totalCourses", 15);
        data.put("totalStudents", 200);
        data.put("totalSelections", 350);
        data.put("passRate", 92.5);
        
        return R.ok().put("data", data);
    }
    
    /**
     * 获取选课趋势数据
     */
    @IgnoreAuth
    @GetMapping("/selection-trend")
    public R getSelectionTrend() {
        List<Map<String, Object>> trend = new ArrayList<>();
        String[] months = {"1月", "2月", "3月", "4月", "5月", "6月"};
        
        for (String month : months) {
            Map<String, Object> item = new HashMap<>();
            item.put("date", month);
            item.put("count", 10 + (int)(Math.random() * 40));
            trend.add(item);
        }
        
        return R.ok().put("data", trend);
    }
    
    /**
     * 获取分数分布数据
     */
    @IgnoreAuth
    @GetMapping("/score-distribution")
    public R getScoreDistribution() {
        List<Map<String, Object>> distribution = new ArrayList<>();
        
        String[] levels = {"优秀", "良好", "中等", "及格", "不及格"};
        int[] counts = {20, 30, 25, 15, 10};
        
        for (int i = 0; i < levels.length; i++) {
            Map<String, Object> item = new HashMap<>();
            item.put("level", levels[i]);
            item.put("count", counts[i]);
            distribution.add(item);
        }
        
        return R.ok().put("data", distribution);
    }
    
    /**
     * 获取热门课程数据
     */
    @IgnoreAuth
    @GetMapping("/top-courses")
    public R getTopCourses() {
        List<Map<String, Object>> courses = new ArrayList<>();
        
        String[] courseNames = {"高等数学", "大学英语", "编程导论", "数据结构", "计算机网络"};
        
        for (int i = 0; i < courseNames.length; i++) {
            Map<String, Object> course = new HashMap<>();
            course.put("rank", i + 1);
            course.put("courseName", courseNames[i]);
            course.put("credit", 4 - (i % 3));
            course.put("semester", i < 3 ? "第一学期" : "第二学期");
            course.put("selectCount", 30 - i * 3);
            course.put("avgScore", 85 - i * 2);
            courses.add(course);
        }
        
        return R.ok().put("data", courses);
    }
    
    /**
     * 获取课程选课数据
     */
    @IgnoreAuth
    @GetMapping("/course-selections")
    public R getCourseSelections() {
        List<Map<String, Object>> data = new ArrayList<>();
        
        String[] courseNames = {"高等数学", "大学英语", "编程导论", "数据结构", "计算机网络"};
        
        for (String courseName : courseNames) {
            Map<String, Object> item = new HashMap<>();
            item.put("name", courseName);
            item.put("value", 10 + (int)(Math.random() * 30));
            data.add(item);
        }
        
        return R.ok().put("data", data);
    }
} 